package com.gexin.controller.system.banner;

import com.gexin.core.web.SystemBaseController;
import com.gexin.model.config.Banner;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.log.Log;

import java.util.List;
@ControllerBind(controllerKey = "/system/banner", viewPath = "WEB-INF/system/banner/")
public class BannerController extends SystemBaseController {
	private static Log log = Log.getLog(BannerController.class);

	public void index(){
		System.out.println(1);
		render("list.html");
	}

	public void list(){
		List<Banner> list = Banner.dao.getList(null);
		success(list);
	}

	public void add(){
		Banner banner = Banner.dao.findById(getPara());
		setAttr("banner",banner);
		render("add.html");
	}

	public void save(){
		Banner banner = getModel(Banner.class,"banner");
		if (getPara("banner.state")==null){
			banner.setState(0);
		}
		if (banner.getId()==null){
			banner.save();
		}else{
			banner.update();
		}
		success();
	}

	public void delete(){
		Banner banner = Banner.dao.findById(getPara());
		try {
			banner.delete();
			success();
		}catch (Exception e){
			fail("删除失败");
		}
	}
}
